package com.learnyou.server.xingzuo.common.util;

import cn.hutool.core.util.StrUtil;

import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Objects;

/**
 * @author heweifeng
 * @Description:
 * @date 2023/3/20 13:48
 */
public class TimeUtil {
    public static String getTimeCategory(String scheduleStartTime) {
        if  (StrUtil.isEmpty(scheduleStartTime)) {
            return null;
        }
        int time = new BigDecimal(StrUtil.replace(scheduleStartTime, ":", ".")).intValue();
        if (time <12) {
            return "上午";
        }else if (time >= 12 && time <18) {
            return "下午";
        }else {
            return "晚上";
        }
    }

    public static Date maxDayTime(Date date) {

        if (Objects.nonNull(date)) {
            try {
                DateFormat dateFormat1 = new SimpleDateFormat("yyyy-MM-dd  23:59:59");
                DateFormat dateFormat2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                Date result = dateFormat2.parse(dateFormat1.format(date));
                return result;
            } catch (Exception ex) {
                return null;
            }
        } else {
            return null;
        }


    }

    public static Date minDayTime(Date date) {
        if (Objects.nonNull(date)) {
            try {
                DateFormat dateFormat1 = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
                DateFormat dateFormat2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                Date result = dateFormat2.parse(dateFormat1.format(date));
                return result;
            } catch (Exception ex) {
                return null;
            }
        } else {
            return null;
        }


    }
}
